<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link rel="stylesheet" href="http://cdn.staticfile.org/cesium/1.69.0/Widgets/widgets.css">
    <link rel="stylesheet" href="../css//index.css">
</head>

<body>
    <div class="fun-menu">
        <button onclick="addHeatmap()">热力图</button>
        <button onclick="flyTo()">飞到</button>
        <button onclick="setRender()">更新渲染方案</button>
        <button onclick="setSource()">更新数据</button>
    </div>
    <div id=cesiumContainer></div>

    <script src="http://cdn.staticfile.org/cesium/1.69.0/Cesium.js"></script>
    <script src="../libs//heatmap//heatmap.min.js"></script>
    <script src="../libs/cpc/index.js"></script>
    <script>
        // 要引入插件heatmap.min.js
        var heatMap = null;
        const map = new cpc.Map({
            container: "cesiumContainer",
            camera: {
                position: {
                    x: 119.3006147,
                    y: 26.0316619,
                    z: 4809,
                },
                angle: {
                    heading: 7.33,
                    pitch: -72.53,
                    roll: 0,
                },
                duration: 3,
                complete: () => {
                    console.log("飞行结束了");
                }
            },
            baseMaps: [
                "http://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer",
            ]
        });
        function addHeatmap() {
            const source = [];
            for (let index = 0; index < 100; index++) {
                const x = 119 + Math.random() * 10;
                const y = 26 + Math.random() * 10;
                const value = Math.random();
                source.push({ x, y, value });
            }
            const renderer = {
                type: "heatmap",
                // field: "crime_count", //缺失，默认为0.2   创建对arcgis图层的解析类
                radius: 30,
                colorStops: [
                    { color: "#563098", ratio: 0.1 },
                    { color: "#5d32a8", ratio: 0.2 },
                    { color: "#6735be", ratio: 0.3 },
                    { color: "#7139d4", ratio: 0.4 },
                    { color: "#7b3ce9", ratio: 0.5 },
                    { color: "#853fff", ratio: 0.6 },
                    { color: "#a46fbf", ratio: 0.7 },
                    { color: "#c29f80", ratio: 0.8 },
                    { color: "#e0cf40", ratio: 0.9 },
                    { color: "#ffff00", ratio: 1 },
                ],
                blur: 0.85,
                maxValue: 1,
                minValue: 0,
                maxOpacity: 0.9,
                minOpacity: 0.1,
            };
            heatMap = new cpc.HeatMap({ name: "热力图", source, renderer });
            map.add(heatMap)
        }
        function setRender() {
            const renderer = {
                type: "heatmap",
                field: "crime_count", //缺失，默认为0.2
                radius: 30,
                colorStops: [
                    { color: "#f00", ratio: 0.1 },
                    { color: "#0f0", ratio: 0.5 },
                    { color: "#00f", ratio: 1 },
                ],
                blur: 0.85,
                maxValue: 1,
                minValue: 0,
                maxOpacity: 0.9,
                minOpacity: 0.1,
            };
            heatMap.setRenderer(renderer);
        }
        function setSource() {
            const source = [];
            for (let index = 0; index < 100; index++) {
                const x = 119 - Math.random() * 10;
                const y = 26 - Math.random() * 10;
                const value = Math.random();
                source.push({ x, y, value });
            }
            heatMap.setSource(source);
        }
        function flyTo() {
            heatMap.flyTo();
        }
       
    </script>
</body>

</html>